package com.example.shixun.service.impl;

import com.example.shixun.dao.ExamDao;
import com.example.shixun.pojo.Exam;
import com.example.shixun.service.ExamService;
import com.example.shixun.utils.PageInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    ExamDao examDao;

    @Override
    public Integer save(Exam exam) {
        return examDao.save(exam);
    }

    @Override
    public PageInfoUtil<Exam> findAll(PageInfoUtil<Exam> pageInfoUtil) {
        PageHelper.startPage(pageInfoUtil.getPageNum(),pageInfoUtil.getPageSize(),pageInfoUtil.getOrderBy());
        List<Exam> list=examDao.findAll(pageInfoUtil.getParams());
        PageInfo<Exam> pageInfo=new PageInfo<Exam>(list);
        /*存入返回值*/
        pageInfoUtil.setPageTotal(pageInfo.getPages());
        pageInfoUtil.setTotal(pageInfo.getTotal());
        pageInfoUtil.setList(list);
        return pageInfoUtil;
    }

    @Override
    public Exam findById(Integer id) {
        return examDao.findById(id);
    }

    @Override
    public Integer addStudent(Integer id) {
        return examDao.addStudent(id);
    }

    @Override
    public Integer subStudent(Integer id) {
        return examDao.subStudent(id);
    }
}
